package com.zycfc.zsf.boot.druid;

import com.alibaba.druid.util.*;
import com.zycfc.zsf.boot.util.text.*;
import java.util.*;
import java.io.*;
import org.slf4j.*;

public class DBPasswordCallback extends DruidPasswordCallback
{
    private static final Logger log;
    private static final long serialVersionUID = 8352871450818066381L;
    
    public void setProperties(final Properties properties) {
        super.setProperties(properties);
        final String pwd = properties.getProperty("password");
        if (!StringUtils.isEmpty(pwd)) {
            try (final InputStream in = DBPasswordCallback.class.getResourceAsStream("/zsf_druid_key.properties")) {
                final String key = getKey(in);
                final String enpassword = DESUtil.decryptHex(key, pwd);
                this.setPassword(enpassword.toCharArray());
            }
            catch (Exception e) {
                DBPasswordCallback.log.error("decrypt password error:", (Throwable)e);
                throw new BadPasswordException("decryptFlag password error");
            }
        }
    }
    
    private static String getKey(final InputStream in) {
        String str = null;
        try {
            final ObjectInputStream objectInputStream = new ObjectInputStream(in);
            str = new String(Base64.getDecoder().decode((byte[])objectInputStream.readObject()), "UTF-8");
        }
        catch (FileNotFoundException e) {
            DBPasswordCallback.log.error("decrypt password getKey FileNotFoundException:", (Throwable)e);
        }
        catch (IOException e2) {
            DBPasswordCallback.log.error("decrypt password getKey IOException:", (Throwable)e2);
        }
        catch (ClassNotFoundException e3) {
            DBPasswordCallback.log.error("decrypt password getKey ClassNotFoundException:", (Throwable)e3);
        }
        return str;
    }
    
    static {
        log = LoggerFactory.getLogger((Class)DBPasswordCallback.class);
    }
}
